import random from 'lodash/random';
import range from 'lodash/range';
import dayjs from 'dayjs';
import {
  makeRecords,
  randomCharactors,
  randomTime,
  slicePage,
  randomItem
} from './mock-util';

import datasource from './datasource';

const ids = datasource.records.filter(
  ({ datasourceType }) => datasourceType === 1
);
const ods =  datasource.records.filter(
  ({ datasourceType }) => datasourceType === 2
);

const fanList = [
  { name: "AA", projectName: "海装新能源重庆万盛南天门32MW工程项目" },
  { name: "AB", projectName: "海为支油新疆达坂城一期49.5MW工程项目" },
  { name: "AC", projectName: "海装新能源内蒙古正镶白旗乌宁巴图一期49.5MW工程项目" },
  { name: "AD", projectName: "中能建投广东韶关南雄犁牛坪50MW工程项目" },
  { name: "AE", projectName: "华能陕西定边一期郝滩50MW工程项目" },
  { name: "AF", projectName: "华能陕西定边二期大沙湾50MW工程项目" },
  { name: "AG", projectName: "中电投陕西靖边白天赐一期24MW工程项目" },
  { name: "AH", projectName: "华能云南富源文笔山40MW工程项目" },
  { name: "AI", projectName: "华能云南富源一把伞48MW工程项目" },
  { name: "AJ", projectName: "华能云南富源胜境48MW工程项目" },
  { name: "AK", projectName: "大唐新疆柴窝堡二期49.5MW工程项目" },
  { name: "AL", projectName: "粤水电新疆达坂城第十二师达坂城50MW工程项目" },
  { name: "AM", projectName: "国投新疆伊吾淖毛湖风电场一期49.5MW工程项目" },
  { name: "AN", projectName: "中国水电江苏如东海上项目（潮间带）100MW示范项目20MW工程项目"},
  { name: "AO", projectName: "华冉新疆哈密烟墩第六风电场一期50MW工程项目" },
  { name: "AP", projectName: "新华水电新疆哈密巴里坤三塘湖一期50MW工程项目" },
  { name: "AQ", projectName: "天山电力新疆哈密三塘湖一期24MW工程项目" },
  { name: "AR", projectName: "特变电工新疆吉木乃一期49.5MW工程项目" },
  { name: "AS", projectName: "大唐国际辽宁昌图三江口48MW工程项目" },
  { name: "AT", projectName: "大唐国际辽宁瓦房店安台48MW工程项目" },
  { name: "AU", projectName: "大唐国际辽宁法库冯贝堡48MW工程项目" },
  { name: "AV", projectName: "中广核内蒙古锡林郭勒盟辉腾梁晨辉48MW项目" },
  { name: "AW", projectName: "龙源内蒙古达茂满都拉诺尔49.5MW工程项目" },
  { name: "AX", projectName: "华能内蒙古通辽珠日河一场三期49.5MW工程项目" },
  { name: "AY", projectName: "华电内蒙古正镶白旗乌宁巴图一期49.5MW工程项目" },
  { name: "AZ", projectName: "国华内蒙古锡林郭勒锡盟三期50MW项目" },
  { name: "Aa", projectName: "大唐华银内蒙古锡林郭勒巴彦乌拉49.5MW工程项目" },
  { name: "Ab", projectName: "北方龙源巴彦淖尔市乌拉特后旗乌力吉乌力吉49.5MW工程项目" },
  { name: "Ac", projectName: "三峡新能源贵州盘县白云河梁子48MW工程项目" },
  { name: "Ad", projectName: "华能湖北随县界山二期72MW工程项目" },
  { name: "Ae", projectName: "大唐重庆丰都三坝49.5MW工程项目" },
  { name: "Af", projectName: "德润河北沧州黄骅100MW工程项目" },
  { name: "Ag", projectName: "华润江苏南通如东东安二期16MW工程项目" },
  { name: "Ah", projectName: "华能陕西定边武茆子100MW工程项目" },
  { name: "Ai", projectName: "海为支油新疆吉木乃县一期49.5MW工程项目" },
  { name: "Aj", projectName: "华电新疆布尔津风电二期49.5MW工程项目" },
  { name: "Ak", projectName: "华能陕西靖边四期49.5MW工程项目" },
  { name: "Al", projectName: "华能陕西靖边三期49.5MW工程项目" },
  { name: "Am", projectName: "华能陕西靖边二期49.5MW工程项目" },
  { name: "An", projectName: "华能陕西靖边一期49.5MW工程项目" },
  { name: "Ao", projectName: "华能陕西定边杨井二期49.5MW工程项目" },
  { name: "Ap", projectName: "华能陕西定边郝滩10MW、周台子10MW分散式工程项目" },
  { name: "Aq", projectName: "中广核云南普洱澜沧甲俫波48MW工程项目" },
  { name: "Ar", projectName: "张北测试机组(H111和H120)" },
  { name: "As", projectName: "2.0MW适应性修改" },
  { name: "At", projectName: "中广核贵州龙里贾拓山60MW工程项目" },
  { name: "Au", projectName: "华电河北尚义二工地50MW发电机组优化技改工程" },
  { name: "Av", projectName: "云南能投云南泸西县孔照普48MW工程项目" },
  { name: "Aw", projectName: "云南能投云南会泽县头道坪48MW工程项目" },
  { name: "Ax", projectName: "云南能投云南会泽县大海梁子48MW工程项目" },
  { name: "Ay", projectName: "云南能投云南泸西永三一期48MW工程项目" },
  { name: "Az", projectName: "华能云南大理沙帽山48MW工程项目" },
  { name: "BA", projectName: "国电新能源云南寻甸清水海49.5MW工程项目" },
  { name: "BB", projectName: "中广核辽宁阜新王四营子48MW工程项目" },
  { name: "BC", projectName: "华能辽宁瓦房店赵屯48MW工程项目" },
  { name: "BD", projectName: "华电辽宁铁岭心田堡48MW工程项目" },
  { name: "BE", projectName: "东源电力山东栖霞风电场8.5MW工程项目" },
  {
    name: "BF",
    projectName: "中电投云南楚雄州禄丰县大黄山(罗锅石、三月三）140MW工程项目"
  },
  { name: "BG", projectName: "察哈尔风电河北尚义花儿台" },
  {
    name: "BH",
    projectName: "华冉新疆哈密烟墩第六风电场二期150MW（第一批50套设备）工程项目"
  },
  { name: "BI", projectName: "海装新能源山西省昔阳西寨200MW工程项目" },
  { name: "BJ", projectName: "华能甘肃酒泉桥湾50MW特许权风电场工程项目" },
  { name: "BK", projectName: "华电江苏连云港灌云100MW工程项目" },
  { name: "BL", projectName: "北方龙源内蒙古辉腾锡勒风电场7*2MW技改工程项目" },
  { name: "BM", projectName: "大唐新疆柴窝堡一期增加1*2MW工程项目" },
  {
    name: "BN",
    projectName: "华能甘肃酒泉安北第三风电场AB区40万千瓦特许权（100MW）工程项目"
  },
  { name: "BO", projectName: "大唐国际江西永修松门山48MW工程项目" },
  { name: "BP", projectName: "海装美国爱荷华州项目" },
  { name: "BQ", projectName: "华电河北尚义二工地49.5MW工程项目" },
  { name: "BR", projectName: "华电吉林大安三期48MW工程项目" },
  { name: "BS", projectName: "三峡新能源吉林大安海坨风电场四期49.5MW工程" },
  { name: "BT", projectName: "华能贵州威宁雪山灼圃48MW工程项目" },
  { name: "BU", projectName: "华能贵州威宁雪山仙水坡48MW工程项目" },
  { name: "BV", projectName: "华能山东蓬莱大柳行一期49.8MW工程项目" },
  { name: "BW", projectName: "山西福光山西宁武盘道梁48MW项目" },
  { name: "BX", projectName: "山西福光山西宁武牛家岭48MW项目" },
  { name: "BY", projectName: "中电投广东徐闻和安49.5MW工程项目" },
  { name: "BZ", projectName: "中广核广东高州68MW工程项目" },
  { name: "Ba", projectName: "国电重庆石柱狮子坪50MW工程项目" },
  { name: "Bb", projectName: "海装新能源重庆武隆850kW分散式工程项目" },
  { name: "Bc", projectName: "东海德迦浙江宁波市檀头山岛25.5MW工程项目" },
  { name: "Bd", projectName: "华能云南富源文笔山40MW工程项目" },
  { name: "Be", projectName: "华电辽宁铁岭李家屯48MW风力发电机组技术改造工程" },
  { name: "Bf", projectName: "华电内蒙古赤峰克什克腾旗乌套海二期100MW工程项目" },
  { name: "Bg", projectName: "华电国际山东肥城安临站、桃园风电一期100MW工程项目" },
  { name: "Bh", projectName: "云南能投云南马龙县对门梁子90MW工程项目" },
  { name: "Bi", projectName: "中广核贵州龙里上坝分散式20MW工程项目" },
  { name: "Bj", projectName: "龙源江苏如东潮间带试验风电场4MW工程项目" },
  { name: "Bk", projectName: "华能江苏如东一期48MW工程项目" },
  {
    name: "Bl",
    projectName: "龙源江苏如东潮间带试验风电场（2台5.0MW样机）10MW工程项目"
  },
  { name: "Bm", projectName: "华冉东方新疆哈密景峡第二风电场C区(北区100MW)工程项目" },
  { name: "Bn", projectName: "中广核贵州桐梓坡渡分散式18MW工程项目" },
  { name: "Bo", projectName: "中广核青海西冷湖30MW工程项目" },
  { name: "Bp", projectName: "华能山东蓬莱大柳行风电二期(49.8MW)工程项目" },
  { name: "Bq", projectName: "中能建投广东韶关南雄犁牛坪50MW工程项目" },
  { name: "Br", projectName: "北方龙源内蒙古锡林郭勒盟朱日和2*2MW技改工程项目" },
  { name: "Bs", projectName: "北方龙源内蒙古察右中旗辉腾锡勒23.1WM工程项目" },
  { name: "Bt", projectName: "华能云南大理扁担山48MW工程项目" },
  { name: "Bu", projectName: "国华宁夏吴忠盐池苏步井200MW工程项目" },
  { name: "Bv", projectName: "华能新疆哈密风电基地200MW风电工程(前10万)项目" },
  {
    name: "Bw",
    projectName: "远鑫新疆哈密十三师红星一牧场三塘湖一期、二期99MW工程项目"
  },
  { name: "Bx", projectName: "华能云南富源一把伞48MW工程项目" },
  { name: "By", projectName: "国华新疆哈密景峡第四风电场600MW工程项目一屏" },
  { name: "Bz", projectName: "东润风电河北围场三道沟48MW工程项目" },
  { name: "CA", projectName: "北方龙源内蒙古乌拉特前旗沙德格50MW工程项目" },
  { name: "CB", projectName: "宁夏电投宁夏太阳山风电场100MW项目" },
  { name: "CC", projectName: "云南能投云南楚雄州大中山40MW工程项目" },
  { name: "CD", projectName: "云南能投云南楚雄州老尖山48MW工程项目" },
  {
    name: "CE",
    projectName: "特变电工新疆哈密风电基地二期景峡第六风电场B区二标段一期50MW工程项"
  },
  {
    name: "CF",
    projectName: "特变电工新疆哈密风电基地二期景峡第六风电场B区二标段二期50MW工程项"
  },
  {
    name: "CG",
    projectName: "海装新能源新疆哈密风电基地二期景峡第六风电场A区一标段100MW工程项"
  },
  {
    name: "CH",
    projectName: "海装新能源新疆哈密风电基地二期景峡第六风电场A区二标段100MW工程项"
  },
  { name: "CI", projectName: "大唐国际辽宁法库检修基地配套风电检修机" },
  { name: "CJ", projectName: "中广核云南大姚凉风坳49.5MW工程项目" },
  {
    name: "CK",
    projectName: "华冉新疆哈密烟墩第六风电场二期150MW（第二批25套设备）工程项目"
  },
  { name: "CL", projectName: "华能新疆哈密风电基地200MW风电工程（后10万）项目" },
  { name: "CM", projectName: "北京瑞启达新能源青海格尔木东出口一、二期100MW工程项目" },
  { name: "CN", projectName: "漳泽电力山西运城绛县富家山一期100MW工程项目" },
  { name: "CO", projectName: "大唐新疆哈密淖毛湖风电场102MW工程项目" },
  { name: "CP", projectName: "海装北美爱荷华28MW项目" },
  { name: "CQ", projectName: "盛天巴里坤三塘湖二期49.5MW工程项目" },
  { name: "CR", projectName: "盛天巴里坤三塘湖一期48MW工程项目" },
  { name: "CS", projectName: "华能四川宁南二期(绿荫塘)50MW工程项目" },
  { name: "CT", projectName: "察哈尔围场德源风电场（48MW）工程" },
  { name: "CU", projectName: "康平辛屯风电场（50MW）工程" },
  { name: "CV", projectName: "华能新疆哈密风电基地200MW风电工程项目" },
  { name: "CW", projectName: "北方龙源技改850" },
  { name: "CX", projectName: "中广核贵州都匀石龙40MW工程项目" },
  { name: "CY", projectName: "察哈尔围场四道沟风电场（48MW）工程" },
  { name: "CZ", projectName: "北方龙源内蒙古察右中旗辉腾锡勒4WM(补充）工程项目" },
  { name: "Ca", projectName: "昌图曲家店（48MW）风电项目工程" },
  { name: "Cb", projectName: "沧县风电一期项目工程（100MW）" },
  { name: "Cc", projectName: "中广核贵州开阳高寨40MW工程项目" },
  {
    name: "Cd",
    projectName: "三峡新能源甘肃省天水张家川风电场二期(50MW)风电场工程项目"
  },
  { name: "Ce", projectName: "三峡新能源四川冕宁铁厂乡70MW风电场工程" },
  { name: "Cf", projectName: "华能国际江苏如东八仙角海上风电场100MW工程项目" },
  { name: "Cg", projectName: "华电山东龙口二期49.8MW风电工程项目" },
  { name: "Ch", projectName: "哈密海新能源十三师三塘湖一期、二期99MW风电场项目" },
  { name: "Ci", projectName: "海峡福建福清兴化湾海上风电样机试验风场10MW项目" },
  { name: "Cj", projectName: "华电山东淄博沂源徐家庄48MW风电场一期工程项目" },
  { name: "Ck", projectName: "中广核山西盂县西烟三期20MW风电场工程项目" },
  { name: "Cl", projectName: "察哈尔围场河北阴河风电场(48MW)工程项目" },
  { name: "Cm", projectName: "盛天巴里坤三塘湖项目" },
  { name: "Cn", projectName: "国华新疆哈密景峡第四风电场600MW工程项目二屏" },
  { name: "Co", projectName: "国华新疆哈密景峡第四风电场600MW工程项目三屏" },
  { name: "Cp", projectName: "国华新疆哈密景峡第四风电场600MW工程项目四屛" },
  { name: "Cq", projectName: "国华新疆哈密景峡第四风电场600MW工程项目五屏" },
  { name: "Cr", projectName: "国华新疆哈密景峡第四风电场600MW工程项目六屏" },
  { name: "Cs", projectName: "华润新能源内黄县润风400MW风电项目试验风电机组" },
  { name: "Ct", projectName: "中航朝阳建平黑水46MW工程项目" },
  { name: "Cu", projectName: "中赢正源内蒙古阿拉善盟孪井滩100MW工程项目" },
  { name: "Cv", projectName: "浩泰新能源河北康保徐五林48MW工程项目" },
  { name: "Cw", projectName: "中船海装新能源新疆哈密十三间房一期49.5MW工程项目" },
  { name: "Cx", projectName: "华电威海苘山风电场48MW工程项目" },
  { name: "Cy", projectName: "神州新疆哈密十三间房49.5MW工程项目" },
  { name: "Cz", projectName: "巴基斯坦信德省WEL项目" },
  { name: "DA", projectName: "中船海装内蒙古锡盟特高压乌达莱475MW工程项目三屏" },
  { name: "DB", projectName: "中广核四川古蔺德耀48MW工程项目" },
  { name: "DC", projectName: "中广核湖北通山大幕山58MW工程项目" },
  { name: "DD", projectName: "中船海装山西寿阳一期48MW工程项目" },
  { name: "DE", projectName: "中科捷高河北张北郝家营100MW工程项目" },
  { name: "DF", projectName: "大唐辽宁昌图天桥山19.5MW工程项目" },
  { name: "DG", projectName: "银风汇利内蒙古包头百灵庙49.8MW工程项目" },
  { name: "DH", projectName: "大唐江西兴国云峰嶂60MW工程项目" },
  { name: "DI", projectName: "国家电投云南丘北老庄科48MW工程项目" },
  { name: "DJ", projectName: "青岛天能内蒙古阿旗别力古台项目100MW工程项目" },
  { name: "DK", projectName: "江西电建新疆老君庙通川二期50MW工程项目" },
  { name: "DL", projectName: "信友新能源新疆昌吉北塔山50MW工程项目" },
  { name: "DM", projectName: "江苏金智新疆木垒乾慧100MW工程项目" },
  { name: "DN", projectName: "江苏金智新疆木垒乾智100MW工程项目" },
  { name: "DO", projectName: "国源江苏宝应柳堡66MW工程项目" },
  { name: "DP", projectName: "H136-2.2MW低风速风力发电机组开发" },
  { name: "DQ", projectName: "中广核江西赣县高峰山一期扩建26.4MW工程项目" },
  { name: "DR", projectName: "中广核江西赣县高峰山二期44MW工程项目" },
  { name: "DS", projectName: "中广核山西太谷范村99MW工程项目" },
  { name: "DT", projectName: "金科新能源新疆昌吉北塔山99MW工程项目" },
  { name: "DU", projectName: "吉电股份青海乌兰50MW工程项目" },
  { name: "DV", projectName: "华电河南新乡延津40MW工程项目" },
  { name: "DW", projectName: "中机国能山西侯马紫金山50MW工程项目" },
  { name: "DX", projectName: "国家电投湖南通道播阳一期50MW工程项目" },
  { name: "DY", projectName: "中广核青海冷湖三期50MW工程项目" },
  { name: "DZ", projectName: "华润山东菏泽鄄城一期100MW工程项目" },
  {
    name: "Da",
    projectName: "国家电投青海海南州特高压外送基地切吉乡一标段200MW工程项目"
  },
  { name: "Db", projectName: "乾元坤宇新疆木垒老君庙一期49.5MW工程项目" },
  { name: "Dc", projectName: "盛世鑫源内蒙锡林郭勒镶黄旗125MW风电项目" },
  { name: "Dd", projectName: "大唐重庆丰都横梁50MW工程项目" },
  { name: "De", projectName: "湖南资兴八面山风电场一期50MW工程项目" },
  { name: "Df", projectName: "京能内蒙古苏尼特300MW工程项目" },
  { name: "Dg", projectName: "华润电力贵州锦屏试验样机项目" },
  { name: "Dh", projectName: "中电建贵州桐梓大顶山47.8MW工程项目" },
  { name: "Di", projectName: "华源电力河北张北多能互补150MW工程项目" },
  { name: "Dj", projectName: "华能福建连城天子壁50.4MW工程项目" },
  { name: "Dk", projectName: "华源电力河北张北兴盛茂150MW工程项目" },
  { name: "Dl", projectName: "华能江苏大丰海上100MW工程项目" },
  { name: "Dm", projectName: "中船海装辽宁大连庄河海上300MW工程项目" },
  { name: "Dn", projectName: "中船海装江苏如东H3#海上400MW工程项目" },
  { name: "Do", projectName: "中广核湖北利川元堡50MW工程项目" },
  { name: "Dp", projectName: "华能贵州息烽南山48MW工程项目" },
  { name: "Dq", projectName: "海装新能源山西省昔阳西寨200MW工程项目" },
  { name: "Dr", projectName: "广西灵山八一茶场100MW工程项目" },
  { name: "Ds", projectName: "中船海装内蒙古锡盟特高压乌达莱475MW工程项目一屏" },
  { name: "Dt", projectName: "中船海装内蒙古锡盟特高压乌达莱475MW工程项目二屏" },
  { name: "Du", projectName: "中船海装新疆木垒老君庙99MW工程项目" },
  { name: "Dv", projectName: "粤电广西武宣县合群一期50MW工程项目" },
  { name: "Dw", projectName: "大唐山东滨州阳信100MW工程项目" },
  { name: "Dx", projectName: "丰远能源黑龙江肇源大兴50MW工程项目" },
  { name: "Dy", projectName: "丰远能源黑龙江肇源新龙顺德二期50MW工程项目" },
  { name: "Dz", projectName: "中广核江西赣县高峰山30MW工程项目" },
  { name: "EA", projectName: "国源江苏宝应鲁垛92.5MW工程项目 " },
  { name: "EB", projectName: "国源江苏金湖安丰99MW工程项目" },
  { name: "EC", projectName: "国源江苏金湖安晟99MW工程项目" },
  { name: "ED", projectName: "国源江苏金湖天润50MW工程项目" },
  { name: "EE", projectName: "国源江苏连云港灌云102MW工程项目" },
  { name: "EF", projectName: "国家电投江苏金湖海新60MW工程项目" },
  { name: "EG", projectName: "华电福建福清海坛海峡100MW工程项目" },
  { name: "EH", projectName: "协鑫江苏如东H15#200MW海上工程项目 " },
  { name: "EI", projectName: "中广核江苏如东H8海上200MW工程项目" },
  { name: "EJ", projectName: "协鑫江苏如东H13#150MW海上工程项目" },
  { name: "EK", projectName: "华能江苏启东H1、H2、H3海上210.8MW工程项目" },
  { name: "EL", projectName: "江苏新能江苏如东H2#二标段150MW海上工程项目" },
  { name: "EM", projectName: "深能内蒙古太仆寺旗400MW第一标段工程项目" },
  { name: "EN", projectName: "蒙能投内蒙古东苏旗巴彦杭盖300MW工程项目" },
  { name: "EO", projectName: "华源电力河北张北三号乡150MW工程项目" },
  { name: "EP", projectName: "国电投内蒙古乌兰察布大板梁第一401.2MW工程项目" },
  { name: "EQ", projectName: "大唐河南滑县300MW工程项目" },
  { name: "ER", projectName: "中船海装山西晋中寿阳二期50MW工程项目" },
  { name: "ES", projectName: "大唐陕西榆林定边胡尖山二期50MW工程项目" },
  { name: "ET", projectName: "中电建青海海西州都兰诺木洪50MW工程项目" },
  { name: "EU", projectName: "豫能河南周口郸城县30MW分散式工程项目" },
  { name: "EV", projectName: "豫能河南鹤壁淇县古灵山50MW工程项目" },
  { name: "EW", projectName: "豫能河南周口西华县20MW分散式工程项目" },
  { name: "EX", projectName: "中能建山西阳泉平定100MW工程项目" },
  { name: "EY", projectName: "大荔和煦陕西渭南大荔官池50MW工程项目" },
  { name: "EZ", projectName: "中电建山西阳泉李家山50MW工程项目" },
  { name: "Ea", projectName: "盛世鑫源内蒙锡林郭勒镶黄旗125MW风电项目" },
  { name: "Eb", projectName: "中能建陕西安塞建坪100MW工程项目" },
  { name: "Ec", projectName: "华电河南安阳滑县70MW工程项目" },
  { name: "Ed", projectName: "卧龙电气宁夏吴忠红寺堡150MW工程项目（第一批10台）" },
  { name: "Ee", projectName: "豫能河南濮阳县8.4MW分散式工程项目" },
  { name: "Ef", projectName: "豫能河南驻马店正阳县28.4MW分散式工程项目" },
  { name: "Eg", projectName: "国家电投山西繁峙县风电清洁能源供暖102MW工程项目" },
  { name: "Eh", projectName: "中电建山西阳泉李家山二期40MW工程项目" },
  { name: "Ei", projectName: "中电建山西长治沁源王和镇50MW工程项目" },
  { name: "Ej", projectName: "华润重庆石柱枫木一期50MW工程项目" },
  { name: "Ek", projectName: "华电湖北武穴大金二期50MW工程项目" },
  { name: "El", projectName: "华润重庆石柱枫木一期50MW、二期20MW工程项目" },
  { name: "Em", projectName: "国家电投重庆丰都五洞岩100MW工程项目" },
  { name: "En", projectName: "海得重庆南川香树岭48.3MW工程项目" },
  { name: "Eo", projectName: "乾元坤宇新疆木垒老君庙一期49.5MW工程项目" },
  { name: "Ep", projectName: "华能陕西定边明水湖100MW工程项目" },
  { name: "Eq", projectName: "国家电投内蒙乌兰察布幸福第三419.2MW工程项目" },
  { name: "Er", projectName: "中赢正源宁夏吴忠太阳山150MW工程项目" },
  { name: "Es", projectName: "大唐辽宁天桥山项目" },
  { name: "Et", projectName: "国源江苏宝应巳丰66MW工程项目" },
  { name: "Eu", projectName: "辉煌枣强县70MW、76MW风电场工程" },
  { name: "Ev", projectName: "国电浙江象山1#海上风电场（一期）254.2MW工程项目" },
  { name: "Ew", projectName: "京能青海海南州切吉乡特高压外送50MW工程项目" },
  { name: "Ex", projectName: "中电投云南楚雄州禄丰县大荒山(三月三）140MW工程项目" }
];

const tasks = makeRecords({
  range: [200, 400],
  fill: i => {
    const execCounts = random(0, 999);
    const outputDatasource = randomItem(ods);
    const inputDatasource = randomItem(ids);
    const inputDataSrouceType = randomItem(['DB', 'FILE'])

    const columns = range(3, 8).map(index => randomCharactors({ min: 2, max: 10 }));
    const results = makeRecords({
      range: [0, 300],
      fill: i => Object.fromEntries(
        columns.map(
          title => [title, randomCharactors({ min: 0, max: 15 })]
        )
      )
    });

    const data = {
      // id
      id: i,
      // 任务名称
      taskName: randomCharactors({ min: 3, max: 8 }),
      // 任务类型 1 即时任务，2 定时任务
      executeType: random(1, 2),
      // 执行频率
      executeDuring: random(1, 60),
      // 执行频率单位
      executeUnit: randomItem(['second', 'minute', 'hour', 'day', 'month', 'week', 'year']),
      // 执行文件
      pythonFilePath: randomCharactors({ min: 10, max: 20 }),
      // 执行文件名
      pythonFileName:  `${randomCharactors({ min: 10, max: 20 })}.py`,
      // 日志路径
      logRootPath:  randomCharactors({ min: 10, max: 20 }),
      // 初始时间
      firstExecuteTime: randomTime(1000 * 60 * 60 * 24 * 30),
      // 任务状态 1 等待执行，2 正在执行, 3 执行完成
      currentTaskStatus: random(1, 3),
      // 执行总次数
      executeTotal: execCounts,
      // 执行成功次数
      executeSuccessCount: random(0, execCounts),
      // 最近执行时间
      modifyTime: randomTime(1000 * 60 * 60 * 24 * 30),
      // 执行结果 1 执行失败，2 执行成功
      executeResult: random(1, 2),
      // 输出数据源id
      outputDatasourceId: outputDatasource.id,
      // 输出数据源表名
      outputTableName: randomItem(outputDatasource.tables, {}).tableName,
      // 数据源类型
      inputDataSrouceType,
      // 执行结果
      results: {
        columns,
        list: results
      },
      // 即时任务数据开始时间
      startTime: undefined,
      // 即时任务数据结束时间
      endTime: undefined,
      // 定时任务时间范围
      second: undefined,
      // 查询字段
      sourceColumn: undefined,
      // 字段类型
      targetColum: undefined
    };

    if (inputDataSrouceType === 'DB') {
      // 输入数据源id
      data.inputDatasourceId = inputDatasource.id;
      // 输入表名
      data.inputTableName = randomCharactors({ min: 3, max: 8 });
      //
      data.windFan = makeRecords({
        range: [random(2, 4)],
        fill: () => randomItem(fanList)
      }).map(({ id }) => id).join(',')
    } else {
      // data.inputPanda = `${randomCharactors({ min: 3, max: 10 })}.txt`
    }

    return data;
  },
  sorter: ({ modifyTime: t1 }, { modifyTime: t2 }) => t2.localeCompare(t1)
})

export default {
  name: 'task',
  records: tasks,
  post_list ({
    name,
    executeType,
    currentTaskStatus,
    pageIndex = 1,
    pageSize = 20,
  }) {
    const result = tasks.filter(
      task => !(
        (name && !task.taskName.includes(name))
        ||
        (executeType && task.executeType !== executeType)
        ||
        (currentTaskStatus && task.currentTaskStatus !== currentTaskStatus)
      )
    );

    return slicePage(result, pageIndex, pageSize);
  },

  post_delete ({ id }) {
    const index = tasks.findIndex(item => item.id === id);
    if (index !== -1) {
      tasks.splice(index, 1);
    }
    return {
      code: 0,
      msg: '',
      data: null
    };
  },

  post_add (params) {
    const data = {
      id: Math.max(...tasks.map(({ id }) => id)) + 1,
      executeTotal: 0,
      executeSuccessCount: 0,
      currentTaskStatus: params.executeType === 1 ? 2 : 1,
      modifyTime: null,
      executeResult: null,
      ...params
    };
    tasks.unshift(data);

    return {
      code: 0,
      msg: '',
      data,
    };
  },

  post_update (params) {
    const index = tasks.findIndex(item => item.id === params.id);
    if (index !== -1) {
      Object.assign(
        tasks[index],
        params
      );
    }
    return {
      code: 0,
      msg: '',
      data: params,
    };
  },

  post_execute (params) {
    const index = tasks.findIndex(item => item.id === params.taskId);
    if (index > -1) {
      const executeResult = random(1, 2);
      Object.assign(
        tasks[index],
        {
          currentTaskStatus: 2,
          executeTotal: tasks[index].executeTotal + 1,
          executeSuccessCount: tasks[index].executeSuccessCount + (executeResult === 2 ? 1 : 0),
          modifyTime: dayjs(new Date()).format('YYYY/MM/DD HH:mm:ss'),
          executeResult,
        }
      );

      if (executeResult !== 2) {
        return {
          code: -1,
          msg: '执行失败',
          data: params,
        };
      }
    }

    return {
      code: 0,
      msg: '执行成功',
      data: params,
    };
  },

  post_info (params) {
    const index = tasks.findIndex(item => item.id === params.id);
    let data = null;

    if (index > -1) {
      const item = tasks[index];
      data = {
        ...item,
        logFileList: (
          range(
            2, 6
          ).map(
            index => randomCharactors({ min: 10, max: 20 })
          ).map(
            v => `/logs/${item.id}/${v}.log`
          )
        ),
        name: item.taskName,
        targetDataList: makeRecords({
          range: [20, 40],
          fill: i => ([
            '2020/01/01 10:12:12',
            '01',
            '001',
            '测试描述',
          ])
        })
      };
    }

    return {
      code: 0,
      msg: '',
      data: data,
    };
  },

  post_edit (params) {
    const index = tasks.findIndex(item => item.id === params.id);
    
    return {
      code: 0,
      msg: '',
      data: tasks[index],
    };
  },

  post_resultDataList (params) {
    const task = tasks.find(item => item.id === params.id);

    if (
      !task
      ||
      !task.results
      ||
      !task.results.list
      ||
      !task.results.list.length
    ) {
      return {
        code: 0,
        msg: '',
        data: null
      };
    }

    const { columns, list } = task.results;
    const { pageIndex, pageSize } = params;

    const { data: { list: data, ...page } } = slicePage(list, pageIndex, pageSize)

    return {
      code: 0,
      msg: '',
      data: {
        ...page,
        columns,
        data
      }
    };
  },

  get_getCurrentTimestamp (params) {
    return {
      code: 0,
      msg: '',
      data: Date.now()
      // data: dayjs('2021-04-08 23:59:50').valueOf()
    };
  },

  get_getWindFanList (params) {
    return {
      code: 0,
      msg: '',
      data: fanList
    };
  }
};
